import axios from 'axios';
import api from './config.js';

const getAiResponse = async (messages) => {
  try {
    const response = await axios.post(`${api.API_BASE_URL}/ai-chat`, { messages });
    if (response.data && response.data.choices) {
      return response.data.choices[0].message;
    }
  } catch (error) {
    console.error("Error communicating with AI API:", error);
    return null;
  }
};

export default getAiResponse;
